/*
 * Log.h
 *
 *  Created on: 2024年9月12日
 *      Author: nwz
 */

#ifndef CODE_LOG_H_
#define CODE_LOG_H_
#ifndef TAG
#define TAG "log"
#endif

#define LOG_BASE(level,...) Log::getInstance().log(level,(const uint8_t*)TAG,__VA_ARGS__)

#define LOG_D(...)	LOG_BASE(Log::LogLevel::DEBUG, __VA_ARGS__)
#define LOG_I(...)	LOG_BASE(Log::LogLevel::INFO, __VA_ARGS__)
#define LOG_W(...)	LOG_BASE(Log::LogLevel::WARN, __VA_ARGS__)
#define LOG_E(...)	LOG_BASE(Log::LogLevel::ERR, __VA_ARGS__)

class Log {
public:
	static Log& getInstance() {
		static Log log;
		return log;
	}

	enum class LogLevel : uint8_t {
		DEBUG, INFO, WARN, ERR
	};

	void setLogLevel(LogLevel level);
	void log(LogLevel level, const uint8_t *tag, const void *fmt, ...);

private:
	LogLevel level = LogLevel::DEBUG;
	Log();
	virtual ~Log();
	char buffer[1024];
};

#endif /* CODE_LOG_H_ */
